package Pages;

import appium1.common.Helper;
import org.openqa.selenium.WebElement;

public class PageLogin {
    private Helper helper;
    public  PageLogin(Helper helper){
        this.helper=helper;
    }
    public WebElement getNameEditText(){
        return helper.findById("net.oschina.app:id/et_login_username");
    }
    public WebElement getPwdEditText(){
        return helper.findById("net.oschina.app:id/et_login_pwd");
    }
    public WebElement getLoginBtn(){
        return helper.findById("net.oschina.app:id/bt_login_submit");
    }

    public WebElement getbackButton(){
    return helper.findById("net.oschina.app:id/ib_navigation_back");
    }
    public void enterName(String name){
     helper.enterText(getNameEditText(),name);
    }

    public  void enterPwd(String pwd){
        helper.enterText(getPwdEditText(),pwd);
    }
    public void clickLoginBtn(){
        helper.click(getLoginBtn());
    }
    public void clearname(){
        helper.clearText(getNameEditText());
    }
    public void clickBackBtn(){
        helper.click(getbackButton());
    }
    public void clearpwd(){
        helper.clearText(getPwdEditText());
    }
    public void login(String name,String pwd){
        helper.enterTextWithPreClear(getNameEditText(),name);
        helper.enterTextWithPreClear(getPwdEditText(),pwd);
        clickLoginBtn();
    }
    public boolean isLoginPage() {
        boolean result = false;
        if (getNameEditText().isDisplayed() && getNameEditText().isEnabled()) {
            return true;
        }
        return result;
    }
}